package task5_12;

import com.sun.beans.decoder.StringElementHandler;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/27 9:01
 * @description:
 */
public class Task512 {

  public static void main(String[] args) {
    System.out.println("请输入英语,单词以空格分开");
    Scanner scanner = new Scanner(System.in);
    String sentence = scanner.nextLine();
    String[] words = sentence.split(" ");

    HashMap<String, Integer> hashMap = new HashMap<String, Integer>();
    for (int i = 0; i < words.length; i++) {
      String key = words[i];
      if (hashMap.containsKey(key)){
        Integer value = hashMap.get(key);
        value += 1;
        //覆盖原有的（hashamap不能重复）
        hashMap.put(key, value);
      } else {
        //集合中不包含该单词，直接添加，value为1
        hashMap.put(key, 1);
      }
    }
   Iterator iterator=hashMap.entrySet().iterator();
   while (iterator.hasNext()){
     Map.Entry<String,Integer> entry=(Entry<String,Integer>) iterator.next();
     String key=entry.getKey();
     Integer value=entry.getValue();
     System.out.println(key+":"+value);
   }
  }
}
